﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RED_NET_Core.Entity;
using System.Data;
using System.Data.SqlClient;
using RED_NET_Core.Helper;
namespace RED_NET_Core.DAL
{
    class News_DAL
    {
        #region[添加新闻]
        //发表日志（level为 0：新闻；1:英雄帖；2：普通日志；3：站内信） （replynum初始都设为0）（sendto只有在 level为3是有效）(time：英雄帖的有效天数）
        /// <summary>
        /// 添加新闻（日志，英雄帖，站内信，新闻）
        /// </summary>
        /// <param name="nDdaily">日志类</param>
        public static int AddNews(News nNews)
        {
            string _smdStr;
            OwnSqlHelper _shp = new OwnSqlHelper();
            _smdStr = "update _Users set _BlogNum=_BlogNum + 1  where _UId = '" + nNews.UId.ToString() + "'";
            int _id;
            try
            {
                _id = nNews.AddItem();
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return _id;
        }
        #endregion
        #region[日志访问人数加一]
        /// <summary>
        /// 日志访问人数加一
        /// </summary>
        /// <param name="_NewsId">日志Id</param>
        public static void AddDailyReadNum(int _NewsId)
        {
            string _smdStr = "update _News set _ReadNum=_ReadNum+1 where _Id='"+_NewsId.ToString()+"'";
            OwnSqlHelper _shp = new OwnSqlHelper();
            try
            {
                _shp.ExecuteNonQuery(_smdStr, CommandType.Text);
            }
            catch(Exception ex)
                {
                    throw ex;
                }
        }
        #endregion
        #region[获取日志访问人数]
        /// <summary>
        /// 获取日志访问人数
        /// </summary>
        /// <param name="_NewsId">日志Id</param>
        /// <returns></returns>
        public static int GetDailyReadNum(int _NewsId)
        {
            string _smdStr = "select _ReadNum from _News where _Id='" + _NewsId.ToString() + "'";
            OwnSqlHelper _shp = new OwnSqlHelper();
            int _ans=-1;
            try
            {
                _ans = Int32.Parse(_shp.ExecuteScalar(_smdStr));
          
            }
            catch (Exception ex)
            {
                throw ex;
            }
       return _ans;

        }
        #endregion
        #region[添加留言]
        /// <summary>
        /// 添加留言
        /// </summary>
        /// <param name="nNews"></param>
        /// <returns></returns>
        public static int AddMessage(News nNews)
        {
            int _id;
            try
            {

                _id = nNews.AddItem();
            }
            catch (Exception ex)
            {
                throw ex;
                return -1;
            }
            return _id;
        }
        #endregion
        #region[添加站内信]
        /// <summary>
        /// 添加站内信
        /// </summary>
        /// <param name="nNews"></param>
        /// <param name="nSendTo"></param>
        /// <param name="nNum"></param>
        public static void AddLetter(News nNews, int[] nSendTo, int nNum)
        {

            int i;
            Letter _letter = new Letter();
            _letter.IsRead = 0; 
            _letter.UIdOfSend = nNews.UId;
            try
            {
                _letter.LetterId = nNews.AddItem();

                for (i = 0; i < nNum; i++)
                {
                    _letter.UIdOfRecv = nSendTo[i];
                    _letter.AddItem();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region[删除站内信]
        /// <summary> 
        /// 删除站内信
        /// </summary>
        /// <param name="nId"></param>
        public static void DeleteLetter(int nId)
        {
            string _smdStr = "delete from _Letter where _Id='" + nId.ToString() + "'";
            try
            {
                OwnSqlHelper _shp = new OwnSqlHelper();
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region[添加评论]
        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="nComment">评论类</param>
        public static int AddComment(Comment nComment)
        {
            int _id;
            _id = nComment.AddItem();
            OwnSqlHelper _shp = new OwnSqlHelper();
            string _smdStr = "update _News set _ReplyNum=_ReplyNum + 1  where _Id = '" + nComment.IdTo.ToString() + "'";
            _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            return _id;
        }
        #endregion
        #region[获取留言列表]
        /// <summary>
        /// 获取留言列表
        /// </summary>
        /// <param name="nUId"></param>
        /// <returns></returns>
        public static DataTable ShowMessageList(int nUId)
        {

            String _smdStr = " select *   from   _News where  _Level=4 and  _IsDeleted = 0 and _MessageTo ='" + nUId.ToString() + "' order by _UpdateTime desc";
            OwnSqlHelper _shp = new OwnSqlHelper();
            DataTable _tdt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            DataColumn _dc;
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_AvatarUrl";
            _dc.ReadOnly = false;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_NickName";
            _dc.ReadOnly = false;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            Users _user = new Users();
            Login_DAL _login = new Login_DAL();
            int i, j;
            for (i = 0; i < _tdt.Rows.Count; i++)
            {
                _user = _login.GetMessageOfUser((int)_tdt.Rows[i]["_UId"]);
                _tdt.Rows[i]["_AvatarUrl"] = "~"+_user.AvatarUrl.Substring(2);
                _tdt.Rows[i]["_NickName"] = _user.NickName;
                string _content = _tdt.Rows[i]["_Content"].ToString();
                for (j = 1; j < _content.Length && j < 10; j++)
                {
                    if (_content[j - 1] == '<' && _content[j] == 'b')
                    {
                        break;
                    }
                }
                if (j == 20 && j < _content.Length)
                {
                    _content = _content.Substring(0, 19) + "……";

                }
                else if (j + 2 < _content.Length && (_content[j - 1] == '<') && (_content[j] == 'b') && (_content[j + 1] == 'r') && (_content[j + 2] == '>'))
                {
                    _content = _content.Substring(0, j - 2) + "……";
                }
                _tdt.Rows[i]["_Content"] = _content;

            }
            return _tdt;

        }
        #endregion

        #region[ 获取日志列表]
        /// <summary>
        /// 获取日志
        /// </summary>
        /// <param name="nUid">用户id</param>
        /// <param name="nStat">stat=1:全部日志，stat=2:关注人日志，stat=0:自己的日志</param>
        /// <returns>从数据库中获得的日志</returns>
        public static DataTable ShowDailyList(int nUId, int nStat)
        {
            Login_DAL _login = new Login_DAL();

            String _smdStr = " select *   from   _News where  _Level=2 and  _IsDeleted = 0 ";
            int i;
            if (nStat == 2)
            {
                DataTable _sdt_Id = _login.GetMyAttentionInfo(nUId,0);
                _smdStr += "and  _UId='" + nUId.ToString() + "'";
                for (i = 0; i < _sdt_Id.Rows.Count; i++)
                {
                    _smdStr += "or _UId='" + _sdt_Id.Rows[i]["_UId"].ToString() + "'";
                }
            }
            else if (nStat == 0)
            {
                _smdStr += "and  _UId='" + nUId.ToString() + "'";
            }
            _smdStr += " order by _UpdateTime desc";
            OwnSqlHelper _shp = new OwnSqlHelper();
            DataTable _tdt = new DataTable();
            try
            {
                _tdt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
                return _tdt;
            }
            if (nStat != 0)
            {

                DataColumn _dc;
                _dc = new DataColumn();
                _dc.DataType = System.Type.GetType("System.String");
                _dc.ColumnName = "_AvatarUrl";
                _dc.ReadOnly = false;
                _dc.Unique = false;
                _tdt.Columns.Add(_dc);
                _dc = new DataColumn();
                _dc.DataType = System.Type.GetType("System.String");
                _dc.ColumnName = "_NickName";
                _dc.ReadOnly = false;
                _dc.Unique = false;
                _tdt.Columns.Add(_dc);
                Users _user = new Users();
                for (i = 0; i < _tdt.Rows.Count; i++)
                {

                    _user = _login.GetMessageOfUser((int)_tdt.Rows[i]["_UId"]);
                    _tdt.Rows[i]["_AvatarUrl"] = "~"+_user.AvatarUrl.Substring(2);
                    _tdt.Rows[i]["_NickName"] = _user.NickName;


                }
            }
            else
            {
                    int j, k;
                for (i = 0; i < _tdt.Rows.Count; i++)
                {
                    string _content = (string)_tdt.Rows[i]["_Content"];
                    string _tcontent = "";
                    for (j = 0; j < _content.Length; j++)
                    {
                        if (_content[j] == '<' && _content[j+1] != 'i' && _content[j+1] != 'b')
                        {
                            while (_content[j] != '>')
                                j++;
                        }
                        else
                            _tcontent += _content[j];
                    }
                    _content = _tcontent;
                    if (_content.Length > 110)
                    {

                        
                       
                        for (j = 0; j < 100; j++)
                        {

                            if (_content[j] == '<' && _content[j + 1] == 'i')
                            {
                                
                                for (k = j + 5; k < _content.Length; k++)
                                {

                                    if ( _content[k] == '>')
                                    {
                                        j = k + 1;
                                        
                                        break;
                                    }
                                }
                             


                            }


                        }

                        _content = _content.Substring(0, j - 1) ;

                       
                    }

                 
 _tdt.Rows[i]["_Content"] = _content;
                }

            }

            return _tdt;
        }
        #endregion
        #region[获取评论列表]
        /// <summary>
        /// 获取评论
        /// </summary>
        /// <param name="nDailyid">被评论的新闻id</param>
        /// <returns>从数据库获取的评论</returns>
        public static DataTable ShowCommentList(int nNewsId)
        {
            string _smdStr = "select * from _Comment where _IdTo = '" + nNewsId.ToString() + "' order by _AddTime asc";
            OwnSqlHelper _shp = new OwnSqlHelper();
            DataTable _tdt = new DataTable();
            try
            {

                _tdt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
               
            }
            DataColumn _dc;
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_AvatarUrl";
            _dc.ReadOnly = false;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            int i;
            Login_DAL _login = new Login_DAL();
            Users _users = new Users();
            for (i = 0; i < _tdt.Rows.Count; i++)
            {
                _users = _login.GetMessageOfUser((int)_tdt.Rows[i]["_UId"]);
                _tdt.Rows[i]["_AvatarUrl"] = "~"+_users.AvatarUrl.Substring(2);
            }
            return _tdt;
        }
        #endregion
        #region[获得收到的站内信列表]
        /// <summary>
        /// 获得收到的站内信
        /// </summary>
        /// <param name="nUId"></param>
        /// <returns>返回包含_UId,_Title,_Content,_IsRead,_Id,_UserName,_AddTime字段的表</returns>
        public static DataTable ShowRecvLetterList(int nUId)
        {
            string _smdStr = "select * from _letter where _UIdOfRecv ='" + nUId.ToString() + "' ";
            OwnSqlHelper _shp = new OwnSqlHelper();
         
            try
            {
                DataTable _dt= _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
           
            DataTable _tdt = new DataTable();
            DataColumn _dc;
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.Int32");
            _dc.ColumnName = "_UId";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.Int32");
            _dc.ColumnName = "_UIdOfRecv";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_Title";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_Content";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_IsRead";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.Int32");
            _dc.ColumnName = "_Id";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_UserName";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.DateTime");
            _dc.ColumnName = "_AddTime";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.Int32");
            _dc.ColumnName = "_NewsId";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_AvatarUrl";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_NickName";
            _dc.ReadOnly = true;
            _dc.Unique = false;
            _tdt.Columns.Add(_dc);

            int i;
            for (i = _dt.Rows.Count - 1; i >= 0; i--)
            {
                DataRow _dr = _tdt.NewRow();
                _dr["_UIdOfRecv"] = (int)_dt.Rows[i]["_UIdOfRecv"];
                _dr["_UId"] = (int)_dt.Rows[i]["_UIdOfSend"];
                Users _user = new Users();
                Login_DAL _login = new Login_DAL();
                _user = _login.GetMessageOfUser((int)_dt.Rows[i]["_UIdOfSend"]);
                _dr["_AvatarUrl"] = _user.AvatarUrl;
                _dr["_NickName"] = _user.NickName;
                _dr["_Id"] = (int)_dt.Rows[i]["_Id"];
                _dr["_NewsId"] = (int)_dt.Rows[i]["_LetterId"];
                int _isRead = (int)_dt.Rows[i]["_IsRead"];
                if (_isRead == 0)
                    _dr["_IsRead"] = "未读";
                else
                    _dr["_IsRead"] = "已读";
                _smdStr = "select * from _News where _Id ='" + _dt.Rows[i]["_LetterId"].ToString() + "'";
                OwnSqlHelper _tmpShp = new OwnSqlHelper();
                DataTable _tmpdt = _tmpShp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
                if (_tmpdt.Rows.Count >= 1)
                {
                    _dr["_Title"] = (string)_tmpdt.Rows[0]["_Title"];
                    _dr["_Content"] = (string)_tmpdt.Rows[0]["_Content"];
                    _dr["_UserName"] = (string)_tmpdt.Rows[0]["_UserName"];
                    _dr["_AddTime"] = (DateTime)_tmpdt.Rows[0]["_AddTime"];
                }
                _tdt.Rows.Add(_dr);
            }
            _tdt.DefaultView.Sort = "_AddTime desc";
            return _tdt;
                 }
            catch (Exception ex)
            {
                throw ex;
               
            }
        }
        #endregion
        #region[获取公告]
        /// <summary>
        /// 获取公告
        /// </summary>
        
        /// <returns></returns>
        public static DataTable GetAnnouncement(int num)
        {
            try
            {
                string _smdStr = "select * from _News  where _Level=0 and _IsDeleted=0 order by _AddTime desc";

                OwnSqlHelper _shp = new OwnSqlHelper();
                DataTable _dt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
                if (num != 0)
                {
                    int i;
                    for (i = num; i < _dt.Rows.Count; i++)
                    {
                        _dt.Rows[i].Delete();
                    }
                }
         
                
                return _dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
          
        }
        #endregion
        #region[删除公告]
        /// <summary>
        /// 删除公告
        /// </summary>
        /// <param name="_Id"></param>
        public static void DeleteAnnouncement(int nId)
        {
            try
            {
                string _smdStr = "update _News set _IsDeleted=1 where _Id ='" + nId.ToString() + "'";
                OwnSqlHelper _shp = new OwnSqlHelper();
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region[判断站内信是否为该用户所有]
        /// <summary>
        /// 判断站内信是否为该用户所有
        /// </summary>
        /// <param name="id"></param>
        /// <param name="news"></param>
        /// <returns></returns>
        public static int JudgeRecvLetter(int uid,int letterId)
        {
            string _smdStr = "select count(*) as _Count from _letter where _LetterId='" + letterId.ToString() + "'";
            OwnSqlHelper _shp = new OwnSqlHelper();
            DataTable _dt = new DataTable();
            try
            {
                _dt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;

            }
           int c=(int)_dt.Rows[0]["_Count"];
           if (c == 0)
           {
               Exception ex=new Exception("JudgeRecvLetterError");
           throw ex;
           }
           else
               return 1;
        }
        #endregion
        #region[获取发出的站内信列表]
        /// <summary>
        /// 获取发出的站内信
        /// </summary>
        /// <param name="nUId"></param>
        /// <returns></returns>
        public static DataTable ShowSendLetterList(int nUId)
        {
            string _smdStr = "select * from _News where _UId ='" + nUId.ToString() + "' and (_Level = 3 or _Level=1 )and _IsDeleted = 0";
            OwnSqlHelper _shp = new OwnSqlHelper();
            
            try
            {

               DataTable _dt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
           

            Login_DAL _login = new Login_DAL();
            Users _users = _login.GetMessageOfUser(nUId);
            DataColumn _dc;
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_AvatarUrl";
            _dc.ReadOnly = false;
            _dc.Unique = false;
            _dt.Columns.Add(_dc);
            _dc = new DataColumn();
            _dc.DataType = System.Type.GetType("System.String");
            _dc.ColumnName = "_NickName";
            _dc.ReadOnly = false;
            _dc.Unique = false;
            _dt.Columns.Add(_dc);
            int i;
            for (i = 0; i < _dt.Rows.Count; i++)
            {
                _dt.Rows[i]["_AvatarUrl"] = _users.AvatarUrl;
                _dt.Rows[i]["_NickName"] = _users.NickName;
            }
            _dt.DefaultView.Sort = "_AddTime desc";
            return _dt;
            }
            catch (Exception ex)
            {
                throw ex;

            }
        }

        #endregion
        #region[获取未读的站内信总数]
        public static int GetLetterNum(int nUId)
        {
            string _smdStr = "select count(*) as _Count from _Letter where _IsRead=0   and _UIdOfRecv='" + nUId.ToString() + "'";
            OwnSqlHelper _shp = new OwnSqlHelper();
            DataTable _dt=new DataTable();
            try
            {
                _dt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
             
            }
            return (int)_dt.Rows[0]["_Count"];

        }
        #endregion
        #region[获取新闻内容]
        public static News ShowNews(int nId)
        {
            if (nId == 0)
            {
                Exception ex=new Exception("Invalid News ID");
                throw ex;
            }
            string _smdStr = "select * from _News where _Id='" + nId.ToString() + "' ";
            OwnSqlHelper _shp = new OwnSqlHelper();  
            News _news = new News();
            DataTable _dt = new DataTable();
            try
            {

                _dt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
                return _news;
            }
         
            _news.AddTime = (DateTime)_dt.Rows[0]["_AddTime"];
            _news.Content = (string)_dt.Rows[0]["_Content"];
            _news.Id = nId;
            _news.Level = (int)_dt.Rows[0]["_Level"];
            _news.ReplyNum = (int)_dt.Rows[0]["_ReplyNum"];
            _news.Time = (int)_dt.Rows[0]["_Time"];
            _news.Title = (string)_dt.Rows[0]["_Title"];
            _news.UId = (int)_dt.Rows[0]["_UId"];
            _news.UpdateTime = (DateTime)_dt.Rows[0]["_UpdateTime"];
            _news.UserName = (string)_dt.Rows[0]["_UserName"];
            _news.SendTo = (string)_dt.Rows[0]["_SendTo"];
            _news.IsDeleted = (bool)_dt.Rows[0]["_IsDeleted"];
            _news.ReadNum = (int)_dt.Rows[0]["_ReadNum"];
            return _news;
        }
        #endregion
        #region[ 删除评论]
        /// <summary>
        /// 删除评论
        /// </summary>
        /// <param name="nId">被评论的新闻id</param>
        public static void DeleteComment(int nId)
        {
            OwnSqlHelper _shp = new OwnSqlHelper();
            string _smdStr = " select _IdTo   from   _Comment  where _Id='" + nId.ToString() + "'";
            DataTable _sdt = new DataTable();
            try
            {
                _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
                return;
            }
            int i;
            for (i = 0; i < _sdt.Columns.Count; i++)
            {
                _smdStr = "update _News set _ReplyNum=_ReplyNum - 1  where _Id = '" + _sdt.Rows[i]["_IdTo"].ToString() + "'";
            }
            try
            {
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
                _smdStr = "delete from _Comment where _Id='" + nId.ToString() + "'";
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        #region[删除新闻]
        /// <summary>
        /// 删除新闻
        /// </summary>
        /// <param name="nId">要删除的新闻id</param>
        public static void DeleteNews(int nId)
        {
            OwnSqlHelper _shp = new OwnSqlHelper();
            string _smdStr = " select _UId   from   _News  where _Id='" + nId.ToString() + "'";
            try
            {  
            DataTable _sdt = _shp.ExecuteQuery(_smdStr, System.Data.CommandType.Text);
            int i;
            for (i = 0; i < _sdt.Columns.Count; i++)
            {
                _smdStr = "update _Users set _BlogNum=_BlogNum - 1  where _UId = '" + _sdt.Rows[i]["_UId"].ToString() + "'";
            }
          
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);

                _smdStr = "update _News set _IsDeleted = 1 where _Id='" + nId.ToString() + "'";
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion
        #region[删除留言]
        /// <summary>
        /// 删除留言
        /// </summary>
        /// <param name="nId"></param>
        public static void DeleteMessage(int nId)
        {
            OwnSqlHelper _shp = new OwnSqlHelper();
            string _smdStr = "update _News set _IsDeleted = 1 where _Id='" + nId.ToString() + "'";
            try
            {
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;

            }

        }
        #endregion
        #region[设置站内信为已读]
        /// <summary>
        /// 设置站内信为已读
        /// </summary>
        /// <param name="nId">设置的letter id</param>
        public static void SetLetterIsRead(int nId)
        {
            OwnSqlHelper _shp = new OwnSqlHelper();
            string _smdStr = "update _Letter set _IsRead = 1 where _Id='" + nId.ToString() + "'";
            try
            {
                _shp.ExecuteNonQuery(_smdStr, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion
        #region[更新日志]
        /// <summary>
        /// 更新日志
        /// </summary>
        /// <param name="nContent">内容</param>
        /// <param name="nTitle">标题</param>
        /// <param name="nId">日志ID</param>
        public static void UpdateDaily(string nContent, string nTitle, int nId)
        {
            SqlParameter[] _param = new SqlParameter[4];
            _param[0] = new SqlParameter("@Content", nContent.ToString());
            _param[1] = new SqlParameter("@Title", nTitle.ToString());
            _param[2] = new SqlParameter("@Id", nId.ToString());
            _param[3] = new SqlParameter("@UpdateTime", System.DateTime.Now.ToString());

            OwnSqlHelper _shp = new OwnSqlHelper();
            string _smdStr = "update _News set _Content = @Content , _Title = @Title,_UpdateTime=@UpdateTime  where _Id =@Id";
            try
            {
                _shp.ExecuteNonQuery(_smdStr, _param, System.Data.CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
        #endregion

    }
}